*************************************************************
* Replication file:											*
* From the streets to the voting booth 						*
* Supplementary material									*
* Authors: Colombo, Ferrara, Dinas, Vassou, Bernardi   		*
*															*
*************************************************************




* INSERT WORKING DIRECTORY:
global wd ""

* Set style for plots
set scheme plotplain
graph set window fontface "Times New Roman"

************************************************
* FIGURE C.1 - Parallel trends, coefficients
************************************************

* original
use "$wd/main_data.dta", clear
xtset town election_year

xtreg rrp_vs i.treated_orig##i.b2014.election_year if regione=="EMILIAROMAGNA", cluster(town)

parmest, label level(90 95)  list(parm label estimate min95 max95 min90 max90) format(estimate min95 max95  min90 max90 %8.2f)  saving("$wd/temporary estimates/est.dta", replace)


use "$wd/temporary estimates/est.dta", replace

keep if parm=="1.treated_orig#1975.election_year" | parm=="1.treated_orig#1980.election_year" | parm=="1.treated_orig#1985.election_year" | parm=="1.treated_orig#1990.election_year" | parm=="1.treated_orig#1995.election_year" | parm=="1.treated_orig#2000.election_year" | parm=="1.treated_orig#2005.election_year" | parm=="1.treated_orig#2010.election_year" | parm=="1.treated_orig#2014.election_year" | parm=="1.treated_orig#2020.election_year" 


gen estimate_year_t=subinstr(parm, "1.treated_orig#", "", .)
gen estimate_year=subinstr(estimate_year_t, ".election_year", "", .)


drop parm estimate_year_t
destring estimate_year, gen(year)

expand 2 if year==2010, gen(dupindicator)
replace year=2014 if dupindicator==1
replace min90=0 if dupindicator==1
replace max90=0 if dupindicator==1
replace min95=0 if dupindicator==1
replace max95=0 if dupindicator==1
replace estimate=0 if dupindicator==1


tw ///
	rcap min95 max95 year, ///
		lc(gs1) ///
		lw(thin) ///
	|| ///
	rcap min90 max90 year, ///
		lc(gs1) ///
		lw(medthick) ///
	|| ///
	scatter estimate year , ///
		lc(gs1) ///
		mc(gs1) ///
		ms(small) ///
		msymbol(D) ///
	, ///
		legend(off) ///
		yline(0, lcolor(gs12) lstyle(foreground)) ///
		xline(2017.5, lcolor(black)) ///
		ytitle("", size(large)) ///
		xtitle(Election, size(large)) ///
		aspect(1) ///
		xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
		ylabel(-16(4)16, grid glcolor(gray%80) labs(large) glw(medium))
graph export "$wd/FigureC1a.pdf",replace

* Adjacent 
use "$wd/main_data.dta", clear
xtset town election_year

* Generate an year dummy
drop if treated_orig==1
drop if election_year<1995

xtreg rrp_vs i.treated_adj##i.b2014.election_year if regione=="EMILIAROMAGNA", cluster(town) 

parmest, label level(90 95)  list(parm label estimate min95 max95 min90 max90) format(estimate min95 max95  min90 max90 %8.2f)  saving("$wd/temporary estimates/est.dta", replace)


use "$wd/temporary estimates/est.dta", replace

keep if parm=="1.treated_adj#1975.election_year" | parm=="1.treated_adj#1980.election_year" | parm=="1.treated_adj#1985.election_year" | parm=="1.treated_adj#1990.election_year" | parm=="1.treated_adj#1995.election_year" | parm=="1.treated_adj#2000.election_year" | parm=="1.treated_adj#2005.election_year" | parm=="1.treated_adj#2010.election_year" | parm=="1.treated_adj#2014.election_year" | parm=="1.treated_adj#2020.election_year" 


gen estimate_year_t=subinstr(parm, "1.treated_adj#", "", .)
gen estimate_year=subinstr(estimate_year_t, ".election_year", "", .)

drop parm estimate_year_t
destring estimate_year, gen(year)

expand 2 if year==2010, gen(dupindicator)
replace year=2014 if dupindicator==1
replace min90=0 if dupindicator==1
replace max90=0 if dupindicator==1
replace min95=0 if dupindicator==1
replace max95=0 if dupindicator==1
replace estimate=0 if dupindicator==1

tw ///
	rcap min95 max95 year, ///
		lc(gs1) ///
		lw(thin) ///
	|| ///
	rcap min90 max90 year, ///
		lc(gs1) ///
		lw(medthick) ///
	|| ///
	scatter estimate year , ///
		lc(gs1) ///
		mc(gs1) ///
		ms(small) ///
		msymbol(D) ///
	, ///
		legend(off) ///
		yline(0, lcolor(gs12) lstyle(foreground)) ///
		xline(2017.5, lcolor(black)) ///
		xtitle(Election, size(large)) ///
		ytitle("", size(large)) ///
		aspect(1) ///
		xlabel(, grid glcolor(gray%80) labsize(medl) glw(medium)) ///
		ylabel(-16(4)16, grid glcolor(gray%80) labsize(medl) glw(medium))
graph export "$wd/FigureC1b.pdf",replace

************************************************
* FIGURE C.2 - Separate treatments
************************************************

use "$wd/main_data.dta", clear
xtset town election_year

foreach level in 95 90 {

* Model 3 - separating treatments
xtreg rrp_vs i.b2014.election_year i.treatment_orig#i.treatment_salvini if regione=="EMILIAROMAGNA", cluster(town) fe
lincomest 0.treatment_orig#1.treatment_salvini, level(95)
parmest, label saving("$wd/temporary estimates/salvini_`level'_emilia.dta", replace)  level(`level')

xtreg rrp_vs i.b2014.election_year i.treatment_orig#i.treatment_salvini if regione=="EMILIAROMAGNA", cluster(town) fe
lincomest 1.treatment_orig#0.treatment_salvini, level(95)
parmest, label saving("$wd/temporary estimates/sardine_`level'_emilia.dta", replace)  level(`level')

xtreg rrp_vs i.b2014.election_year i.treatment_orig#i.treatment_salvini if regione=="EMILIAROMAGNA", cluster(town) fe
lincomest 1.treatment_orig#1.treatment_salvini, level(95)
parmest, label saving("$wd/temporary estimates/doubletreat_`level'_emilia.dta", replace)  level(`level')

}


foreach model in salvini_ sardine_ doubletreat_ {
	foreach level in 95 90 {

	use "$wd/temporary estimates/`model'`level'_emilia.dta", clear
	gen model = "`model'"

	save "$wd/temporary estimates/`model'`level'_emilia.dta", replace

	}
}

foreach level in 95 90 {

	clear
	foreach model in salvini_ sardine_ doubletreat_ {
	append using "$wd/temporary estimates/`model'`level'_emilia.dta"
	}
save "$wd/temporary estimates/`level'_intervals_emilia.dta", replace

}

use "$wd/temporary estimates/95_intervals_emilia.dta", clear
merge 1:1 model using "$wd/temporary estimates/90_intervals_emilia", nogen
keep model estimate min95 min90 max95 max90 label
order model label


generate model_2=.

replace model_2=3 if model=="sardine_"
replace model_2=2 if model=="salvini_"
replace model_2=1 if model=="doubletreat_"

cap label drop model_lbl
label define model_lbl ///
	3 "Sardine" 2 "Salvini" 1 "Salvini vs. Sardine", replace
label values model_2 model_lbl

* Producing graph
tw rcap min90 max90 model_2, ///
	horizontal ///
	ysc(reverse) ///
	lw(medthick) ///
	lc(gs1) ///
|| rcap min95 max95 model_2, ///
	horizontal ysc(reverse) ///
	lw(thin) ///
	lc(gs1) ///
|| 	scatter model_2 estimate,  ///
	ysc(reverse) ///
	lc(gs1) ///
	mc(gs1) ///
	msymbol(D) ///
	xtitle("", size(large)) ///
	ytitle("") ///
	legend(off) ///
	xline(0, lcolor(gs12)) ///
	xscale(range(-11 11)) ///
	xlabel(-10(2)10, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	ylabel(1 "Sardine" 2 "Salvini" 3 "Sardine vs. Salvini", grid glcolor(gray%80) labs(medl) glw(medium)  angle(horizontal)) ///
	yscale(range(0.5 3.5)) ///
	graphregion(margin(0 0 0 0)) ///
	fysize(80) ///
	subtitle("Sardine vs. Salvini", box fcolor(gs14) bexpand size(large)) ///
	name(plot, replace)
graph display plot, ysize(4)	

		
graph export "$wd/FigureC2.pdf", replace


************************************************
* FIGURE C.3 - Placebo Permutation Test
************************************************

* Original 

use "$wd/main_data.dta", clear

set seed 12345

* randomly select an year of treatment

keep if regione=="EMILIAROMAGNA"

xtreg rrp_vs i.b2014.election_year i.treatment_orig, cluster(town) fe
* Main model estimate=-3.906338

drop if treated_orig==1

* Generate 500 random estimates per year

foreach year in 1995 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {
	
		display `i'

		preserve 
			
			collapse town, by(provincia comune)
			drop town
			
			* generate 28 treated out of 307 observation (9%)
			
			gen treat=runiform(0,1)<0.09
			fre treat
			
			save "$wd/temporary estimates/permutation_muni", replace
			
			use "$wd/main_data.dta", clear

			drop if treated_orig==1
			tab election_year, gen(year)
			drop if election_year<1995
			keep if regione=="EMILIAROMAGNA"
			
			merge m:1 provincia comune using "$wd/temporary estimates/permutation_muni"
			drop _merge
			
			replace treat=0 if election_year!=`year'
			
			

			xtset town election_year

			xtreg rrp_vs i.b2014.election_year i.treat, cluster(town) fe
			
			parmest, label list(parm label estimate) format(estimate %8.2f)  saving("$wd/temporary estimates/permutation_`year'_`i'.dta", replace)

		restore

	}
}

use "$wd/temporary estimates/permutation_1995_1.dta", replace 

forvalues i = 2/500 {

	append using "$wd/temporary estimates/permutation_1995_`i'.dta"
}

foreach year in 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {

		append using "$wd/temporary estimates/permutation_`year'_`i'.dta"
		
	}
}

keep if parm=="1.treat"

* Plot estimates
histogram estimate, ///
	xline(-3.990864, lcolor(gs1) lwidth(thick)) ///
	xline(0, lcolor(black)) ///
	xtitle(,size(vlarge)) ///
	color(black%30) ///
	xlabel(, grid glcolor(gray%80) labs(mdel) glw(medium)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ytitle("")
graph export "$wd/FigureC3a.pdf", replace

use "$wd/main_data.dta", clear

set seed 12345

* randomly select an year of treatment

keep if regione=="EMILIAROMAGNA"
drop if treated_orig==1

xtreg rrp_vs i.b2014.election_year i.treatment_adj, cluster(town) fe
* Main model estimate=
drop if treated_adj==1

* Generate 500 random estimates per year

foreach year in 1995 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {
	
		display `i'

		preserve 
			
			collapse town, by(provincia comune)
			drop town
			
			* generate 28 treated out of 385 observation (53%)
			
			gen treat=runiform(0,1)<0.53
			
			fre treat
			
			save "$wd/temporary estimates/permutation_muni", replace
			
			use "$wd/main_data.dta", clear

			drop if treated_adj==1
			tab election_year, gen(year)
			drop if election_year<1995
			keep if regione=="EMILIAROMAGNA"
			
			merge m:1 provincia comune using "$wd/temporary estimates/permutation_muni"
			drop _merge
			
			replace treat=0 if election_year!=`year'

			xtset town election_year

			xtreg rrp_vs i.b2014.election_year i.treat, cluster(town) fe
			
			parmest, label list(parm label estimate) format(estimate %8.2f)  saving("$wd/temporary estimates/permutation_`year'_`i'.dta", replace)

		restore

	}
}

use "$wd/temporary estimates/permutation_1995_1.dta", replace 

forvalues i = 2/500 {

	append using "$wd/temporary estimates/permutation_1995_`i'.dta"
}

foreach year in 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {

		append using "$wd/temporary estimates/permutation_`year'_`i'.dta"
		
	}
}

keep if parm=="1.treat"

* Plot estimates
histogram estimate, ///
	xline(-2.878477, lcolor(gs1) lwidth(thick)) ///
	xline(0, lcolor(black)) ///
	xtitle(,size(vlarge)) ///
	color(black%30) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ytitle("")
graph export "$wd/FigureC3b.pdf", replace

*/
************************************************
* FIGURE C.4 - Sensitivity analysis
************************************************


use "$wd/main_data.dta", clear


tempname memhold
postfile `memhold' str32 comune beta se low up p using "$wd/temporary estimates/emi_main_comuni.dta" , replace
levelsof comune if region=="EMILIAROMAGNA", local(levels) 
 foreach l of local levels {
 
xtreg rrp_vs i.b2014.election_year treatment_orig if regione=="EMILIAROMAGNA" & comune != "`l'", cluster(town) fe 

    local b = _b[treatment_orig]
    local se = _se[treatment_orig]
    test treatment_orig
	local low = _b[treatment_orig] - invttail(e(df_r),0.025)*_se[treatment_orig]
	local up =  _b[treatment_orig] + invttail(e(df_r),0.025)*_se[treatment_orig]
    local p=r(p)
    post `memhold' (`"`l'"') (`b') (`se') (`low') (`up') (`p')
}
postclose `memhold'


preserve

	use "$wd/temporary estimates/emi_main_comuni.dta", clear
	encode comune,gen(com)
	sum com

	tw rcap low up com, ///
		horizontal ///
		lw(vvthin) ///
		lc(gs1) ///
		ysc(reverse) ///
	||	scatter com beta,  ///
		xline(0, lcolor(gs12)) ///
		ytitle("Municipality-sensitive models", size(vlarge)) ///
		legend(off) ///
		ylabel(, nolabels noticks) ///
		xtitle("ATT", size(large)) ///
		xlabel(-12(2)2, grid glcolor(gray%80) labs(medl) glw(medium)) ///
		ylabel(1 340, grid glcolor(gray%80) labs(medl) glw(medium)) ///
		lc(gs1) ///
		mc(gs1) ///
		msymbol(D) ///
		msize(tiny) ///
		title("") ///
		aspect(1.5)
		
		graph export "$wd/FigureC4a.pdf", replace
		
restore

* adjacent

tempname memhold
postfile `memhold' str32 comune beta se low up p using "$wd/temporary estimates/emi_main_comuni.dta" , replace
drop if treated_adj==.
levelsof comune if region=="EMILIAROMAGNA", local(levels) 
 foreach l of local levels {
 
xtreg rrp_vs i.b2014.election_year treatment_adj if regione=="EMILIAROMAGNA" & comune != "`l'", cluster(town) fe 

    local b = _b[treatment_adj]
    local se = _se[treatment_adj]
    test treatment_adj
	local low = _b[treatment_adj] - invttail(e(df_r),0.025)*_se[treatment_adj]
	local up =  _b[treatment_adj] + invttail(e(df_r),0.025)*_se[treatment_adj]
    local p=r(p)
    post `memhold' (`"`l'"') (`b') (`se') (`low') (`up') (`p')
}
postclose `memhold'


preserve

	use "$wd/temporary estimates/emi_main_comuni.dta", clear
	encode comune,gen(com)
	sum com

	tw rcap low up com, ///
		horizontal ///
		lw(vvthin) ///
		lc(gs1) ///
		ysc(reverse) ///
	||	scatter com beta,  ///
		xline(0, lcolor(gs12)) ///
		ytitle("Municipality-sensitive models", size(large)) ///
		legend(off) ///
		ylabel(1 313, nolabels noticks) ///
		xtitle("ATT", size(large)) ///
		xlabel(-12(2)2, grid glcolor(gray%80) labs(medl) glw(medium)) ///
		lc(gs1) ///
		aspect(1.5) ///
		mc(gs1) ///
		msymbol(D) ///
		msize(tiny) ///
		title("")
		graph export "$wd/FigureC4b.pdf", replace

restore

************************************************
* TABLE C.1 - Results
************************************************
********** Original treatment ***********
* LOAD AND PREPARE THE DATA
use "$wd/main_data.dta", clear

set matsize 10000
eststo clear

*Emilia - Normal
summ rrp_vs if election_year==2020 & treated_orig==0 & region=="EMILIAROMAGNA"
local mean = r(mean)

eststo: xtreg rrp_vs i.b2014.election_year treatment_orig if regione=="EMILIAROMAGNA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "No"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean


eststo: xtreg rrp_vs i.b2014.election_year treatment_orig town##c.election_year#c.election_year if regione=="EMILIAROMAGNA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "Yes"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean


* Emilia - lagged
summ rrp_vs if election_year==2014 & treated_orig==0 & region=="EMILIAROMAGNA"
local mean = r(mean)

eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_orig if regione=="EMILIAROMAGNA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "No"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean

eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_orig town##c.election_year#c.election_year if regione=="EMILIAROMAGNA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "Yes"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean


* Exporting
esttab using "$wd/TableC1.tex", booktabs replace label nogaps keep(treatment_orig) ///
	mtitles("Far-right$_{(t)}" "Far-right$_{(t)}" "Far-right$_{(t-1)}" "Far-right$_{(t-1)}" ) ///
	scalars("mean Vote to FRP in control group" "a \hline"  "fe Municipality FE" "fe_2 Election FE" "trend Municipality trends" "z \hline" ///
	"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(treatment_orig ATT) obslast ///
	mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
	suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p

est clear


************************************************
* TABLE C.2 - Results adjacent
************************************************

preserve 

	drop if treated_orig==1

	*Emilia - Normal
	summ rrp_vs if election_year==2020 & treated_adj==0 & region=="EMILIAROMAGNA"
	local mean = r(mean)

	xtreg rrp_vs i.b2014.election_year##i.treated_adj if regione=="EMILIAROMAGNA", cluster(town)

	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "No"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd scalar clusters
	estadd scalar elections
	estadd scalar mean


	eststo: xtreg rrp_vs i.b2014.election_year treatment_adj town##c.election_year#c.election_year if regione=="EMILIAROMAGNA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "Yes"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd local clusters
	estadd local elections
	estadd local mean


	* Emilia - lagged
	summ rrp_vs if election_year==2014 & treated_adj==0 & region=="EMILIAROMAGNA"
	local mean = r(mean)

	eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_adj if regione=="EMILIAROMAGNA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "No"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd local clusters
	estadd local elections
	estadd local mean

	eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_adj town##c.election_year#c.election_year if regione=="EMILIAROMAGNA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "Yes"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd local clusters
	estadd local elections
	estadd local mean

	esttab using "$wd/TableC2.tex", ///
		booktabs ///
		replace ///
		label ///
		nogaps ///
		keep(treatment_adj) ///
		mtitles("Far-right$_{(t)}" "Far-right$_{(t)}" "Far-right$_{(t-1)}" "Far-right$_{(t-1)}" ) ///
		scalars(mean fe fe_2 trend r2_o elections N_clust) ///
		varlabels(treatment_adj ATT) ///
		obslast ///
		nonumber ///
		p


	* Exporting
	esttab using "$wd/TableC2.tex", booktabs replace label nogaps keep(treatment_adj) ///
		mtitles("Far-right$_{(t)}" "Far-right$_{(t)}" "Far-right$_{(t-1)}" "Far-right$_{(t-1)}" ) ///
		scalars("mean Vote to RRP in control group" "a \hline"  "fe Municipality FE" "fe_2 Election FE" "trend Municipality trends" "z \hline" ///
		"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(treatment_adj ATT) obslast ///
		mgroups("Emilia Romagna" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
		suffix(}) span erepeat( \cmidrule(lr){@span})) nonumber p
		
		
	est clear
	
restore

************************************************
* TABLE C.3  - Separate treatments
************************************************

* original and salvini
sum rrp_vs if election_year==2020 & treatment_orig==0 & region=="EMILIAROMAGNA"
local mean = r(mean)

eststo: xtreg rrp_vs i.b2014.election_year i.treatment_orig##i.treatment_salvini if regione=="EMILIAROMAGNA", cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "No"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean

* Exporting
esttab using "$wd/TableC3.tex", booktabs replace label nogaps keep(1.treatment_orig 1.treatment_salvini 1.treatment_orig#1.treatment_salvini) ///
	mtitles("Far-right$_{(t)}") ///
	scalars("mean Vote to RRP in control group" "a \hline"  "fe Municipality FE" "fe_2 Election FE" "trend Municipality trends" "z \hline" ///
	"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(1.treatment_orig "Sardine" 1.treatment_salvini "Salvini" 1.treatment_orig#1.treatment_salvini "Sardine \times Salvini") obslast ///
	mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
	suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p
	
est clear

************************************************
* FIGURE D.1 - Alternative electoral outcomes
************************************************

eststo clear
foreach outcome in turnout cr_vs rrp_vs cl_vs rlp_vs civic_vs civic_vs populist_vs {
	
	eststo: xtreg `outcome' i.b2014.election_year treatment_orig ///
	if regione=="EMILIAROMAGNA" , cluster(town) fe

}

coefplot (est1, rename(treatment_orig=treatment_orig_1) msymbol(D) ///
mcolor("gs1")) ///
(est2, rename(treatment_orig=treatment_orig_2) msymbol(D) ///
mcolor("gs1")) ///
(est3, rename(treatment_orig=treatment_orig_3) msymbol(D) ///
mcolor("gs1")) ///
(est4, rename(treatment_orig=treatment_orig_4) msymbol(D) ///
mcolor("gs1")) /// 
(est5, rename(treatment_orig=treatment_orig_5) msymbol(D) ///
mcolor("gs1")) ///
(est6, rename(treatment_orig=treatment_orig_6) msymbol(D) ///
mcolor("gs1")) ///
(est7, rename(treatment_orig=treatment_orig_7) msymbol(D) ///
mcolor("gs1")) ///
, keep(treatment_orig*) legend(off) ///
	levels(90 95) ///
		ciopts(lwidth(*2.4 *1.2 ) lcolor(gs1 gs1)) ///
coeflabels(treatment_orig_1 = "{bf:Turnout}" ///
treatment_orig_2 = "Center-right vote share" ///
treatment_orig_3 = "Far-right vote share" ///
treatment_orig_4 = "Center-left vote share" ///
treatment_orig_5 = "Far-left vote share" ///
treatment_orig_6 = "Civic list vote share" ///
treatment_orig_7 = "Populist vote share") ///
xline(0, lcolor("gs12")) xtitle("ATT of Sardine events (% point change)" ) ///
yline(1.5, lcolor("black") lpattern(solid)) ///
ytitle("", height(6))
graph export "$wd/FigureD1.pdf", replace


************************************************
* FIGURE E.1.a - Population parallel trends
************************************************

use "$wd/pt_population_1991_2022", replace
local varlab "`:var label population_tot'"
xtset id_city_istat election_year

* original lines
xtreg population_tot i.b2014.election_year##i.treated_orig if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(1995 2000 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	xline(2017.5, lcolor(black)) ///
	ytitle("`varlab'", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureE1a.pdf", replace

************************************************
* FIGURE E.1.b, .c, .d - Population parallel trends
************************************************

local fig_pop_less30 "b"
local fig_pop_30_59 "c"
local fig_pop_more60 "d"

foreach v in pop_less30 pop_30_59 pop_more60{


use "$wd/population_clean", replace
local varlab "`:var label `v''"

xtset id_city_istat election_year

* original lines
xtreg `v' i.b2014.election_year##i.treated_orig if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(1995 2000 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	xline(2017.5, lcolor(black)) ///
	ytitle("`varlab'", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureE1`fig_`v''.pdf", replace


}
 ************************************************
* FIGURE E.2 - Taxable income parallel trends
************************************************

use "$wd/taxable_income_clean", replace
local varlab "`:var label pc_taxable_income'"
xtset id_city_istat election_year

* original lines
xtreg pc_taxable_income i.b2012.election_year##i.treated_orig if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(2013 2014 2015 2016 2017 2018 2019 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	ytitle("Taxable income per capita", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureE2.pdf", replace

************************************************
* FIGURE E.3 - Foreign population parallel trends
************************************************


use "$wd/pt_population_1991_2022", replace
local varlab "Foreign residents (share)"
xtset id_city_istat election_year

* original lines
xtreg foreign_share i.b2014.election_year##i.treated_orig if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(  2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	ytitle("`varlab'", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureE3.pdf", replace


************************************************
* FIGURE F.1.a - Population parallel trends - adjacent
************************************************

use "$wd/pt_population_1991_2022", replace
drop if treated_orig==1
local varlab "`:var label population_tot'"
xtset id_city_istat election_year

* adjacent lines
xtreg population_tot i.b2014.election_year##i.treated_adj if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(1995 2000 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	xline(2017.5, lcolor(black)) ///
	ytitle("`varlab'", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureF1a.pdf", replace

************************************************
* FIGURE F.1.b, .c, .d - Population parallel trends - adjacent
************************************************

local fig_pop_less3030 "b"
local fig_pop_30_59 "c"
local fig_pop_more60 "d"


foreach v in pop_less30 pop_30_59 pop_more60{

use "$wd/population_clean", replace
drop if treated_orig==1
local varlab "`:var label `v''"
xtset id_city_istat election_year

* adjacent lines
xtreg `v' i.b2014.election_year##i.treated_adj if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(1995 2000 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	xline(2017.5, lcolor(black)) ///
	ytitle("`varlab'", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureF1`fig_`v''.pdf", replace

}


************************************************
* FIGURE F.2 - Taxable income parallel trends - adjacent
************************************************

use "$wd/taxable_income_clean", replace
local varlab "`:var label pc_taxable_income'"
xtset id_city_istat election_year

xtreg pc_taxable_income i.b2012.election_year##i.treated_adj if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=(2013 2014 2015 2016 2017 2018 2019 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
		xline(2019.5, lcolor(black)) ///
	ytitle("Taxable income per capita", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureF2.pdf", replace

************************************************
* FIGURE F.3 - Foreign population parallel trends - adjacent
************************************************

use "$wd/pt_population_1991_2022", replace
local varlab "Foreign residents (share)"
xtset id_city_istat election_year

* adjacent lines
xtreg foreign_share i.b2014.election_year##i.treated_adj if regione=="EMILIAROMAGNA", cluster(id_city_istat)
margins, at(election_year=( 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	ytitle("`varlab'", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium) ) ///	
	title("", size(large)) ///
	legend( ///
		region(lwidth(none)) ///
		size(medl) ///
		col(2) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureF3.pdf", replace

************************************************
* FIGURE G.1 - Parallel trends - CALABRIA
************************************************

* Original
use "$wd/main_data.dta", clear


* original
xtreg rrp_vs i.b2014.election_year##i.treated_orig if regione=="CALABRIA", cluster(town)
margins, at(election_year=(1995 2000 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor(gs1) lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	ytitle("FRP vote share", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	yscale(range(0 30))  ylabel(0(10)50) ///
	title("", size(large)) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	legend( ///
		region(lwidth(none)) ///
		col(2) ///
		size(medl) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureG1a.pdf", replace

* adjecent
xtreg rrp_vs i.b2014.election_year##i.treated_adj if regione=="CALABRIA", cluster(town)
margins, at(election_year=(1995 2000 2005 2010 2014 2020) treated = (0 1))
marginsplot, ///
	plot1opts(msymbol(D) mcolor("gs12") fcolor("gs12") lcolor("gs12") msize(medsmall) lwidth(med)) ///
	ci1opts(lcolor("gs12") lwidth(medthick)) ///
	plot2opts(msymbol(O) mcolor("gs1") fcolor("gs1") lcolor("gs1") msize(medsmall) lwidth(med))  ///
	ci2opts(lcolor("gs1") lwidth(medthick)) ///
	aspect(1) ///	
	ytitle("FRP vote share", height(5) size(large)) ///
	xtitle("Election", height(5) size(large)) ///
	yscale(range(0 30))  ylabel(0(10)50) ///
	title("", size(large)) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	legend( ///
		region(lwidth(none)) ///
		col(2) ///
		size(large) ///
		position(6) ///
		order(3 "Control" 4 "Treated"))	
graph export "$wd/FigureG1b.pdf", replace

************************************************
* FIGURE G.2 - Parallel trends - coefficients - CALABRIA
************************************************

* Original
use "$wd/main_data.dta", clear

* Generate an year dummy
reg rrp_vs i.treated_orig##i.b2014.election_year if regione=="CALABRIA"

parmest, label level(90 95)  list(parm label estimate min95 max95 min90 max90) format(estimate min95 max95  min90 max90 %8.2f)  saving("$wd/temporary estimates/est.dta", replace)


use "$wd/temporary estimates/est.dta", replace

keep if parm=="1.treated_orig#1975.election_year" | parm=="1.treated_orig#1980.election_year" | parm=="1.treated_orig#1985.election_year" | parm=="1.treated_orig#1990.election_year" | parm=="1.treated_orig#1995.election_year" | parm=="1.treated_orig#2000.election_year" | parm=="1.treated_orig#2005.election_year" | parm=="1.treated_orig#2010.election_year" | parm=="1.treated_orig#2014.election_year" | parm=="1.treated_orig#2020.election_year" 


gen estimate_year_t=subinstr(parm, "1.treated_orig#", "", .)
gen estimate_year=subinstr(estimate_year_t, ".election_year", "", .)

drop parm estimate_year_t
destring estimate_year, gen(year)

expand 2 if year==2010, gen(dupindicator)
replace year=2014 if dupindicator==1
replace min90=0 if dupindicator==1
replace max90=0 if dupindicator==1
replace min95=0 if dupindicator==1
replace max95=0 if dupindicator==1
replace estimate=0 if dupindicator==1

tw ///
	rcap min95 max95 year, ///
		lc(gs1) ///
		lw(thin) ///
	|| ///
	rcap min90 max90 year, ///
		lc(gs1) ///
		lw(medthick) ///
	|| ///
	scatter estimate year , ///
		lc(gs1) ///
		mc(gs1) ///
		ms(small) ///
		msymbol(D) ///
	, ///
		legend(off) ///
		yline(0, lcolor(gs12) lstyle(foreground)) ///
		xline(2017.5, lcolor(black)) ///
		aspect(1) ///
		xtitle(Election, size(large)) ///
		xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
		ylabel(-16(4)16, grid glcolor(gray%80) labs(medl) glw(medium)) 
graph export "$wd/FigureG2a.pdf",replace

* Adjacent

use "$wd/main_data.dta", clear

* Generate an year dummy

drop if treated_orig==1
drop if election_year<1995

xtreg rrp_vs i.treated_adj##i.b2014.election_year if regione=="CALABRIA", cluster(town)

parmest, label level(90 95)  list(parm label estimate min95 max95 min90 max90) format(estimate min95 max95  min90 max90 %8.2f)  saving("$wd/temporary estimates/est.dta", replace)


use "$wd/temporary estimates/est.dta", replace

keep if parm=="1.treated_adj#1975.election_year" | parm=="1.treated_adj#1980.election_year" | parm=="1.treated_adj#1985.election_year" | parm=="1.treated_adj#1990.election_year" | parm=="1.treated_adj#1995.election_year" | parm=="1.treated_adj#2000.election_year" | parm=="1.treated_adj#2005.election_year" | parm=="1.treated_adj#2010.election_year" | parm=="1.treated_adj#2014.election_year" | parm=="1.treated_adj#2020.election_year" 


gen estimate_year_t=subinstr(parm, "1.treated_adj#", "", .)
gen estimate_year=subinstr(estimate_year_t, ".election_year", "", .)

drop parm estimate_year_t
destring estimate_year, gen(year)

expand 2 if year==2010, gen(dupindicator)
replace year=2014 if dupindicator==1
replace min90=0 if dupindicator==1
replace max90=0 if dupindicator==1
replace min95=0 if dupindicator==1
replace max95=0 if dupindicator==1
replace estimate=0 if dupindicator==1


tw ///
	rcap min95 max95 year, ///
		lc(gs1) ///
		lw(thin) ///
	|| ///
	rcap min90 max90 year, ///
		lc(gs1) ///
		lw(medthick) ///
	|| ///
	scatter estimate year , ///
		lc(gs1) ///
		mc(gs1) ///
		ms(small) ///
		msymbol(D) ///
	, ///
		legend(off) ///
		yline(0, lcolor(gs12) lstyle(foreground)) ///
		xline(2017.5, lcolor(black)) ///
		aspect(1) ///
		xtitle(Election, size(large)) ///
		xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
		ylabel(-16(4)16, grid glcolor(gray%80) labs(medl) glw(medium)) 
graph export "$wd/FigureG2b.pdf",replace

************************************************
* FIGURE G.3 - RESULTS COEFPLOT - CALABRIA
************************************************

use "$wd/main_data.dta", clear
xtset town election_year

foreach level in 95 90 {

	* Model 1 - main
	xtreg rrp_vs i.b2014.election_year treatment_orig if regione=="CALABRIA" , cluster(town) fe
	lincomest treatment_orig, level(`level')
	parmest, label saving("$wd/temporary estimates/main_`level'_calabria.dta", replace) level(`level')

	* Model 1 - main + municipality trends
	xtreg rrp_vs i.b2014.election_year treatment_orig town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
	lincomest treatment_orig, level(`level')
	parmest, label saving("$wd/temporary estimates/main_trend_`level'_calabria.dta", replace) level(`level')

	* Placebo 1
	xtreg rrp_vs_lag i.b2014.election_year treatment_orig if regione=="CALABRIA" , cluster(town) fe
	lincomest treatment_orig, level(`level')
	parmest, label saving("$wd/temporary estimates/placebo_main_`level'_calabria.dta", replace) level(`level')

	* Placebo 1 + trends
	xtreg rrp_vs_lag i.b2014.election_year treatment_orig town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
	lincomest treatment_orig, level(`level')
	parmest, label saving("$wd/temporary estimates/placebo_main_trend_`level'_calabria.dta", replace) level(`level')

	* Model 2 - Only adjacent
	preserve
		drop if treated_adj==.
		xtreg rrp_vs i.b2014.election_year treatment_adj if regione=="CALABRIA" , cluster(town) fe
		lincomest treatment_adj, level(`level')
		parmest, label saving("$wd/temporary estimates/adjacent_`level'_calabria.dta", replace) level(`level')
	restore

	* Model 2 - Only adjacent + trends

	preserve
		drop if treated_adj==.
		xtreg rrp_vs i.b2014.election_year treatment_adj town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
		lincomest treatment_adj, level(`level')
		parmest, label saving("$wd/temporary estimates/adjacent_trend_`level'_calabria.dta", replace) level(`level')
	restore

	* Placebo 2
	preserve
		drop if treated_adj==.
		xtreg rrp_vs_lag i.b2014.election_year treatment_adj if regione=="CALABRIA" , cluster(town) fe
		lincomest treatment_adj, level(`level')
		parmest, label saving("$wd/temporary estimates/placebo_adjacent_`level'_calabria.dta", replace) level(`level')
	restore

	* Placebo 2 + trends
	preserve
		drop if treated_adj==.
		xtreg rrp_vs_lag i.b2014.election_year treatment_adj town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
		lincomest treatment_adj, level(`level')
		parmest, label saving("$wd/temporary estimates/placebo_adjacent_trend_`level'_calabria.dta", replace) level(`level')
	restore

	* Model 3 - separating treatments
	xtreg rrp_vs i.b2014.election_year i.treatment_orig#i.treatment_salvini if regione=="CALABRIA", cluster(town) fe
	lincomest 0.treatment_orig#1.treatment_salvini, level(95)
	parmest, label saving("$wd/temporary estimates/salvini_`level'_calabria.dta", replace)  level(`level')

	xtreg rrp_vs i.b2014.election_year i.treatment_orig#i.treatment_salvini if regione=="CALABRIA", cluster(town) fe
	lincomest 1.treatment_orig#0.treatment_salvini, level(95)
	parmest, label saving("$wd/temporary estimates/sardine_`level'_calabria.dta", replace)  level(`level')

	xtreg rrp_vs i.b2014.election_year i.treatment_orig#i.treatment_salvini if regione=="CALABRIA", cluster(town) fe
	lincomest 1.treatment_orig#1.treatment_salvini, level(95)
	parmest, label saving("$wd/temporary estimates/doubletreat_`level'_calabria.dta", replace)  level(`level')

}


foreach model in main_ main_trend_ placebo_main_ placebo_main_trend_ adjacent_ adjacent_trend_  placebo_adjacent_  placebo_adjacent_trend_ salvini_ sardine_ doubletreat_ {
	foreach level in 95 90 {

		use "$wd/temporary estimates/`model'`level'_calabria.dta", clear
		gen model = "`model'"

		save "$wd/temporary estimates/`model'`level'_calabria.dta", replace

	}
}

foreach level in 95 90 {
	use "$wd/temporary estimates/main_`level'_calabria.dta", clear

	foreach model in main_trend_ placebo_main_ placebo_main_trend_ adjacent_ adjacent_trend_  placebo_adjacent_  placebo_adjacent_trend_ salvini_ sardine_ doubletreat_ {
		append using "$wd/temporary estimates/`model'`level'_calabria.dta"
		}
	save "$wd/temporary estimates/`level'_intervals_calabria.dta", replace

	}

use "$wd/temporary estimates/95_intervals_calabria.dta", clear
merge 1:1 model using "$wd/temporary estimates/90_intervals_calabria", nogen
keep model estimate min95 min90 max95 max90 label
order model label


generate model_2=.
replace model_2=10 if model=="main_"
replace model_2=12 if model=="main_trend_"
replace model_2=14 if model=="placebo_main_"
replace model_2=16 if model=="placebo_main_trend_"


replace model_2=22 if model=="adjacent_"
replace model_2=24 if model=="adjacent_trend_"
replace model_2=26 if model=="placebo_adjacent_"
replace model_2=28 if model=="placebo_adjacent_trend_"

replace model_2=34 if model=="sardine_"
replace model_2=36 if model=="salvini_"
replace model_2=38 if model=="doubletreat_"

cap label drop model_lbl
label define model_lbl ///
	10 "M11. Main treatment" 12 "M12. + Municipality trends"14  "M13. Placebo" 16 "M14. Placebo + municipality trends" ///
	22 "M15. Adjacent treatment" 24 "M16. + Municipality trends" 26 "M17. Placebo" 28 "M18. Placebo + municipality trends" ///
	34 "M19. Only Sardine events" 36 "M19. Only Salvini events" 38 "M19. Both Salvini and Sardine events"
label values model_2 model_lbl

* Producing graph
tw rcap min90 max90 model_2, ///
	horizontal ///
	ysc(reverse) ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ylabel(10 12 14 16 22 24 26 28 34 36 38, valuelabel grid glcolor(gray%80) labs(medl) glw(medium)) ///
	lw(medthick) ///
	lc(gs1) ///
|| rcap min95 max95 model_2, ///
	horizontal ysc(reverse) ///
	ylabel(10 12 14 16 22 24 26 28 34 36 38, valuelabel grid glcolor(gray%80) labs(medl) glw(medium)) ///
	lw(thin) ///
	lc(gs1) ///
|| 	scatter model_2 estimate,  ///
	ysc(reverse) ///
	lc(gs1) ///
	mc(gs1) ///
	msymbol(D) ///
	xtitle("FRP vote share", size(large)) ///
	ytitle("") ///
	legend(off) ///
	xline(0, lcolor(gs12))

		
graph export "$wd/FigureG3.pdf", replace


************************************************
* TABLE G.1 - Results original - CALABRIA
************************************************

********** Original treatment ***********
* LOAD AND PREPARE THE DATA
use "$wd/main_data.dta", clear

set matsize 10000
eststo clear

*Calabria - Normal
summ rrp_vs if election_year==2020 & treated_orig==0 & region=="CALABRIA"
local mean = r(mean)

eststo: xtreg rrp_vs i.b2014.election_year treatment_orig if regione=="CALABRIA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "No"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean


eststo: xtreg rrp_vs i.b2014.election_year treatment_orig town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "Yes"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean


* Calabria - lagged
summ rrp_vs if election_year==2014 & treated_orig==0 & region=="CALABRIA"
local mean = r(mean)

eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_orig if regione=="CALABRIA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "No"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean

eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_orig town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "Yes"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean


* Exporting
esttab using "$wd/TableG1.tex", booktabs replace label nogaps keep(treatment_orig) ///
	mtitles("Far-right$_{(t)}" "Far-right$_{(t)}" "Far-right$_{(t-1)}" "Far-right$_{(t-1)}" ) ///
	scalars("mean Vote to FRP in control group" "a \hline"  "fe Municipality FE" "fe_2 Election FE" "trend Municipality trends" "z \hline" ///
	"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(treatment_orig ATT) obslast ///
	mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
	suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p

est clear

************************************************
* TABLE G.2 - Results adjecent - CALABRIA
************************************************

preserve 

	drop if treated_orig==1

	*Calabria - Normal
	summ rrp_vs if election_year==2020 & treated_adj==0 & region=="CALABRIA"
	local mean = r(mean)

	eststo: xtreg rrp_vs i.b2014.election_year treatment_adj if regione=="CALABRIA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "No"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd scalar clusters
	estadd scalar elections
	estadd scalar mean


	eststo: xtreg rrp_vs i.b2014.election_year treatment_adj town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "Yes"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd scalar clusters
	estadd scalar elections
	estadd scalar mean


	* Calabria - lagged
	summ rrp_vs if election_year==2014 & treated_adj==0 & region=="CALABRIA"
	local mean = r(mean)

	eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_adj if regione=="CALABRIA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "No"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd scalar clusters
	estadd scalar elections
	estadd scalar mean

	eststo: xtreg rrp_vs_lag i.b2014.election_year treatment_adj town##c.election_year#c.election_year if regione=="CALABRIA" , cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	estadd local trend "Yes"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	scalar mean = `mean'
	estadd scalar clusters
	estadd scalar elections
	estadd scalar mean

	* Exporting
	esttab using "$wd/TableG2.tex", booktabs replace label nogaps keep(treatment_adj) ///
		mtitles("Far-right$_{(t)}" "Far-right$_{(t)}" "Far-right$_{(t-1)}" "Far-right$_{(t-1)}" ) ///
		scalars("mean Vote to RRP in control group" "a \hline"  "fe Municipality FE" "fe_2 Election FE" "trend Municipality trends" "z \hline" ///
		"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(treatment_adj ATT) obslast ///
		mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
		suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p
		
	est clear
	
restore

************************************************
* TABLE G.3 - Separate treatments - CALABRIA
************************************************

* original and salvini
summ rrp_vs if election_year==2020 & treatment_orig==0 & region=="CALABRIA"
local mean = r(mean)

eststo: xtreg rrp_vs i.b2014.election_year i.treatment_orig##i.treatment_salvini if regione=="CALABRIA", cluster(town) fe
estadd local fe "Yes"
estadd local fe_2 "Yes"
estadd local trend "No"
scalar clusters = e(N_g)
scalar elections = e(g_max)
scalar mean = `mean'
estadd scalar clusters
estadd scalar elections
estadd scalar mean

* Exporting
esttab using "$wd/TableG3.tex", booktabs replace label nogaps keep(1.treatment_orig 1.treatment_salvini 1.treatment_orig#1.treatment_salvini) ///
	mtitles("Far-right$_{(t)}") ///
	scalars("mean Vote to RRP in control group" "a \hline"  "fe Municipality FE" "fe_2 Election FE" "trend Municipality trends" "z \hline" ///
	"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(1.treatment_orig "Sardine" 1.treatment_salvini "Salvini" 1.treatment_orig#1.treatment_salvini "Sardine \times Salvini") obslast ///
	mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
	suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p
	
est clear

************************************************
* FIGURE G.4 - Placebo permutation test - CALABRIA
************************************************

* Original
use "$wd/main_data.dta", clear

set seed 12345

* randomly select an year of treatment

keep if regione=="CALABRIA"

xtreg rrp_vs i.b2014.election_year i.treatment_orig, cluster(town) fe
* Main model estimate=-4.257789

drop if treated_orig==1

* Generate 500 random estimates per year

foreach year in 1995 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {
	
		display `i'

		preserve 
			
			collapse town, by(provincia comune)
			drop town
			
			* generate 4 treated out of 399 observation (1%)
			
			gen treat=runiform(0,1)<0.01
			
			fre treat
			
			save "$wd/temporary estimates/permutation_muni", replace
			
			use "$wd/main_data.dta", clear

			drop if treated_orig==1
			tab election_year, gen(year)
			drop if election_year<1995
			keep if regione=="CALABRIA"
			
			merge m:1 provincia comune using "$wd/temporary estimates/permutation_muni"
			drop _merge
			
			replace treat=0 if election_year!=`year'

			xtset town election_year

			xtreg rrp_vs i.b2014.election_year i.treat, cluster(town) fe
			
			parmest, label list(parm label estimate) format(estimate %8.2f)  saving("$wd/temporary estimates/permutation_`year'_`i'.dta", replace)

		restore

	}
}

use "$wd/temporary estimates/permutation_1995_1.dta", replace 

forvalues i = 2/500 {

	append using "$wd/temporary estimates/permutation_1995_`i'.dta"
}

foreach year in 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {

		append using "$wd/temporary estimates/permutation_`year'_`i'.dta"
		
	}
}

keep if parm=="1.treat"

* Plot estimates
histogram estimate, ///
	xline(-4.257789, lcolor(gs1)) ///
	xline(0, lcolor(gs12)) ///
	color(black%30) /// 
	xtitle(, size(large)) ///
	ytitle("") ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium)) 

graph export "$wd/FigureG3a.pdf", replace

* Adjecent
use "$wd/main_data.dta", clear

set seed 12345

* randomly select an year of treatment

keep if regione=="CALABRIA"
drop if treated_orig==1

xtreg rrp_vs i.b2014.election_year i.treatment_adj, cluster(town) fe
* Main model estimate=-4.652918

drop if treated_adj==1

* Generate 500 random estimates per year

foreach year in 1995 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {
	
		display `i'

		preserve 
			
			collapse town, by(provincia comune)
			drop town
			
			* generate 31 treated out of 395 observation (8%)
			
			gen treat=runiform(0,1)<0.08
			fre treat
			
			save "$wd/temporary estimates/permutation_muni", replace
			
			use "$wd/main_data.dta", clear

			drop if treated_adj==1
			tab election_year, gen(year)
			drop if election_year<1995
			keep if regione=="CALABRIA"
			
			merge m:1 provincia comune using "$wd/temporary estimates/permutation_muni"
			drop _merge
			
			replace treat=0 if election_year!=`year'

			xtset town election_year

			xtreg rrp_vs i.b2014.election_year i.treat, cluster(town) fe
			
			parmest, label list(parm label estimate) format(estimate %8.2f)  saving("$wd/temporary estimates/permutation_`year'_`i'.dta", replace)

		restore

	}
}

use "$wd/temporary estimates/permutation_1995_1.dta", replace 

forvalues i = 2/500 {

	append using "$wd/temporary estimates/permutation_1995_`i'.dta"
}

foreach year in 2000 2005 2010 2014 2020{

	forvalues i = 1/500 {

		append using "$wd/temporary estimates/permutation_`year'_`i'.dta"
		
	}
}

keep if parm=="1.treat"

* Plot estimates
histogram estimate, ///
	xline(-4.652918, lcolor(gs1)) ///
	xline(0, lcolor(gs12)) ///
	xlabel(, grid glcolor(gray%80) glw(medium) labs(medl)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medl)) ///
	color(black%30) ///
	xtitle(, size(large)) ///
	ytitle("")
graph export "$wd/FigureG3b.pdf", replace

************************************************
* FIGURE G.5 - Sensitivity analysis - CALABRIA
************************************************

use "$wd/main_data.dta", clear

* Original
tempname memhold
postfile `memhold' str32 comune beta se low up p using "$wd/temporary estimates/cal_main_comuni.dta", replace
levelsof comune if region=="CALABRIA", local(levels) 
 foreach l of local levels {
 
xtreg rrp_vs i.b2014.election_year treatment_orig if regione=="CALABRIA" & comune != "`l'", cluster(town) fe 

    local b = _b[treatment_orig]
    local se = _se[treatment_orig]
    test treatment_orig
	local low = _b[treatment_orig] - invttail(e(df_r),0.025)*_se[treatment_orig]
	local up =  _b[treatment_orig] + invttail(e(df_r),0.025)*_se[treatment_orig]
    local p=r(p)
    post `memhold' (`"`l'"') (`b') (`se') (`low') (`up') (`p')
}
postclose `memhold'


preserve

	use "$wd/temporary estimates/cal_main_comuni.dta", clear
	encode comune, gen(com)

	tw rcap low up com, ///
		horizontal ///
		lw(vvthin) ///
		lc(gs1) ///
		ysc(reverse) ///
	||	scatter com beta,  ///
		xline(0, lcolor(gs12)) ///
		ytitle("Municipality-sensitive models", size(large)) ///
		legend(off) ///
		ylabel(, nolabels noticks) ///
		xtitle("ATT", size(large)) ///
		xlabel(-20(5)5, grid glcolor(gray%80) labs(medl) glw(medl)) ///
		lc(gs1) ///
		aspect(1) ///
		mc(gs1) ///
		msymbol(D) ///
		msize(tiny) ///
		title("")
		graph export "$wd/FigureG5a.pdf", replace

restore
	
* adjacent 

tempname memhold
postfile `memhold' str32 comune beta se low up p using "$wd/temporary estimates/cal_main_comuni.dta" , replace
levelsof comune if region=="CALABRIA", local(levels) 
 foreach l of local levels {
 
xtreg rrp_vs i.b2014.election_year treatment_adj if regione=="CALABRIA" & comune != "`l'", cluster(town) fe 

    local b = _b[treatment_adj]
    local se = _se[treatment_adj]
    test treatment_adj
	local low = _b[treatment_adj] - invttail(e(df_r),0.025)*_se[treatment_adj]
	local up =  _b[treatment_adj] + invttail(e(df_r),0.025)*_se[treatment_adj]
    local p=r(p)
    post `memhold' (`"`l'"') (`b') (`se') (`low') (`up') (`p')
}
postclose `memhold'


preserve

	use "$wd/temporary estimates/cal_main_comuni.dta", clear
	encode comune,gen(com)

	tw rcap low up com, ///
		horizontal ///
		lw(vvthin) ///
		lc(gs1) ///
		ysc(reverse) ///
	||	scatter com beta,  ///
		xline(0, lcolor(gs12)) ///
		ytitle("Municipality-sensitive models", size(large)) ///
		legend(off) ///
		ylabel(, nolabels noticks) ///
		xtitle("ATT", size(large)) ///
		xlabel(-12(2)2, grid glcolor(gray%80) labs(medl) glw(medl)) ///
		lc(gs1) ///
		aspect(1) ///
		mc(gs1) ///
		msymbol(D) ///
		msize(tiny) ///
		title("")
		graph export "$wd/FigureG5b.pdf", replace

restore

************************************************
* FIGURE H.1 - Histogram interaction variables
************************************************
clear all
use "$wd/main_data.dta", replace

keep if election_year==2020 & region=="EMILIAROMAGNA"

label var enp_2014 "Left ENP, 2014"
label var left_vs_14 "Avg. left votes, 1995-2014"
label var pd_left_14 "PD/Left, 2014"

local fig_enp_2014 "a"
local fig_pd_left_14 "b"
local fig_left_vs_14 "c"

foreach he in enp_2014 pd_left_14 left_vs_14{
	
histogram `he', ///
	color(black%30) /// 
	xtitle(, size(large)) ///
	ytitle("") ///
	xlabel(, grid glcolor(gray%80) labs(medl) glw(medium)) ///
	ylabel(, grid glcolor(gray%80) labs(medl) glw(medium)) 
graph export "$wd/Figureh1`fig_`he''.pdf", replace

}

************************************************
* Table H.1 - Heterogeneous effects - EMILIA
************************************************

* for the manuscript	
clear all
use "$wd/main_data.dta", replace
xtset town 
foreach he in enp_2014 pd_left_14 left_vs_14{
	
	egen he=std(`he')
	label var he "Moderator"
		
	eststo: xtreg rrp_vs i.b2014.election_year i.treatment_orig##c.he if regione=="EMILIAROMAGNA", cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	estadd scalar clusters
	estadd scalar elections
	
	drop he

}

* Exporting
esttab using "$wd/TableH1.tex", booktabs replace label nogaps keep(1.treatment_orig 1.treatment_orig#c.he) ///
	mtitles("Left ENP, 2014" "PD/left, 2014" "Left votes, 1995-2014") ///
	scalars("fe Municipality FE" "fe_2 Election FE" ///
	"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(1.treatment_orig "Sardine" 1.treatment_orig#he "Sardine \times Moderator") obslast ///
	mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
	suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p
	
************************************************
* Table H.2 - Heterogeneous effects, tercile - EMILIA
************************************************

* Tercile
clear all
use "$wd/main_data.dta", replace
xtset town election_year

label define tercile_lbl 2 "2nd tercile" 3 "3rd tercile"

foreach he in enp_2014 pd_left_14 left_vs_14{
	
	egen tercile=xtile(`he'), n(3)
	label var tercile "Moderator"
	label values tercile tercile_lbl
		
	eststo: xtreg rrp_vs i.b2014.election_year i.treatment_orig##i.tercile if regione=="EMILIAROMAGNA", cluster(town) fe
	estadd local fe "Yes"
	estadd local fe_2 "Yes"
	scalar clusters = e(N_g)
	scalar elections = e(g_max)
	estadd scalar clusters
	estadd scalar elections
	
	drop tercile

}

* Exporting
esttab using "$wd/TableH2.tex", booktabs replace label nogaps keep(1.treatment_orig 1.treatment_orig#2.tercile 1.treatment_orig#3.tercile) ///
	mtitles("Left ENP, 2014" "PD/left, 2014" "Left votes, 1995-2014") ///
	scalars("fe Municipality FE" "fe_2 Election FE" ///
	"r2_o R-squared" "elections Elections" "clusters Clusters") varlabels(1.treatment_orig "Sardine" 1.treatment_orig#he "Sardine \times Moderator") obslast ///
	mgroups("" , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) ///
	suffix(}) span erepeat(\cmidrule(lr){@span})) nonumber p

